package a66weding.com.jiehuntong.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.HashMap;
import java.util.List;

import a66weding.com.jiehuntong.R;

/**
 * Created by admin on 2016/7/28.
 */
public class DeleteTaskAdapter extends BaseAdapter {

    private Context context;
    private List<String> list;
    private static HashMap<Integer, Boolean> isSelected;

    public DeleteTaskAdapter(Context context, List<String> list) {
        this.context = context;
        this.list = list;
        isSelected = new HashMap<>();
        initDate();
    }
    // 初始化isSelected的数据
    private void initDate() {
        for (int i = 0; i < list.size(); i++) {
            getIsSelected().put(i, false);
        }
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if(convertView == null){
            convertView = View.inflate(context, R.layout.diy_item_add,null);
            holder = new ViewHolder();
            holder.cb = (CheckBox) convertView.findViewById(R.id.item_cb);
            holder.iv = (ImageView) convertView.findViewById(R.id.item_iv_selece);
            holder.tv = (TextView) convertView.findViewById(R.id.item_tv);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.tv.setText(list.get(position));
        holder.cb.setChecked(getIsSelected().get(position));

        return convertView;
    }
    public class ViewHolder{
        public TextView tv;
        public CheckBox cb;
        public ImageView iv;
    }
    public static HashMap<Integer, Boolean> getIsSelected() {
        return isSelected;
    }
    public static void setIsSelected(HashMap<Integer, Boolean> isSelected) {
        DeleteTaskAdapter.isSelected = isSelected;
    }

}
